<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>修改个人信息</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="../css/font.css">
		<link rel="stylesheet" href="../css/xadmin.css">
		<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../js/xadmin.js"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>
		<div class="x-body">
			<form class="layui-form" id="editForm">
				<div class="layui-input-inline" style="display: none;">
					<input type="text" id="id" name="userId"  readonly="readonly" lay-verify="required" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-form-item">
					<label for="username" class="layui-form-label">
						<span class="x-red">*</span>登录名
					</label>
					<div class="layui-input-inline">
						<input type="text" id="username" name="username" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="L_pass" class="layui-form-label">
						<span class="x-red">*</span>密码
					</label>
					<div class="layui-input-inline">
						<input type="text" id="password" name="password" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-block">
						<input type="radio" name="sex" value="1" title="男">
						<input type="radio" name="sex" value="0" title="女">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="note" class="layui-form-label">
						<span class="x-red">*</span>签名
					</label>
					<div class="layui-input-inline">
						<input type="text" id="note" name="note" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button type="button" onclick="doSave();" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						<div id="rigisterHint" style="color:red"></div>
					</div>
					
				</div>
				
			</form>
		</div>
		<script>
			var date = eval('('+parent.json+')');//获取父级参数
			console.log(date);
			layui.use('form', function () {
			     var $ = layui.jquery, form = layui.form;
				 $("input[name=sex][value=1]").attr("checked", date.sex == 1 ? true : false);
				 $("input[name=sex][value=0]").attr("checked", date.sex == 0 ? true : false);
				 form.render(); //更新全部 
			    });
			//提交表单
			function doSave() {
				//alert("add");
				//发送post请求
				//  语法：$.post(url,data,callback,type);
				//   url(必须):发送请求的地址，String类型
				//   data(可选):发送给后台的数据，以key/value形式{a:value1,b:value2}，即json格式
				//  callback(可选):请求成功后的回调函数。因此，在后台的处理中，需要给JSONObject put一个是否成功的值，见下面例子。
				//   type(可选):即第二个参数data的数据类型。如果有data传递给后台，则需要加上该类型。
				var data = $("#editForm").serialize();
				$.post("http://localhost:8888/usedcar/user/edit?token="+document.cookie.split(";")[0], data, function(response) {
					console.log(response);
					if (response == 1) {
						layer.alert("修改成功", {
							yes: function() {
								parent.layer.closeAll();
							}
						});
					} else if (response == 0) {
						//用户名不正确
						$("#rigisterHint").html("<b>用户名已被注册</b>");
					} else if (response == -2) {
						//
						$("#rigisterHint").html("<b>必填项不能为空</b>");
					}
				});
			}
		</script>

	</body>

</html>
